import { BroadCastCall } from "../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../Framework/MQ/MessageBlock";
import { SFightAttribute } from "../../../../Message/Public/SFightAttribute";
import { EPublicCommand } from "../../../../Message/Command/EPublicCommand";
import { Cache } from "../../cache/Cache";
import { CareerUtil } from "../../view/common/util/CareerUtil";
import { AttributeValue } from "../../scene/player/AttributeValue";
import { AttributeTextType } from "../../scene/player/type/AttributeTextType";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { RolePlayer } from "../../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../../scene/events/PlayerEvent";
//class FightAttributeCommand
    
    export  class FightAttributeCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            var loc9=null;
            var loc1=arg1.messageBase as SFightAttribute;
            if (_cache.role.fightAttribute && type == EPublicCommand._ECmdPublicFightAttribute) 
            {
                loc2 = _cache.role.fightAttribute;
                loc3 = ["physicalAttack", "magicAttack", "physicalDefense", "magicDefense", "physicalCrit", "magicCrit", "hit", "jouk", "pass", "block", "speededUp", "toughness", "maxLife", "maxMana"];
                loc4 = Vector.<String>(loc3);
                loc7 = 0;
                while (loc7 < loc4.length) 
                {
                    loc5 = loc4[loc7];
                    if (loc1[loc5] != loc2[loc5]) 
                    {
                        loc6 = Cache.instance.role.entityInfo.careerEnable;
                        if (!(loc5 == "magicAttack" && CareerUtil.isPhysicalCareer(loc6))) 
                        {
                            if (!(loc5 == "physicalAttack" && CareerUtil.isMagicCareer(loc6))) 
                            {
                                loc8 = int(loc1[loc5]) - int(loc2[loc5]);
                                if (!(Cache.instance.role.entityInfo.level <= 10 && loc8 <= -200)) 
                                {
                                };
                                loc9 = new AttributeValue(AttributeTextType[loc5], loc8 > 0, loc8 > 0 ? loc8 : -1 * loc8);
                                NetDispatcher.dispatchCmd(ServerCommand.RoleSingleAttributeChange, loc9);
                            }
                        }
                    }
                    ++loc7;
                }
            }
            _cache.role.fightAttribute = loc1;
            NetDispatcher.dispatchCmd(ServerCommand.RoleFightAttributeChange, _cache.role.fightAttribute);
            _cache.role.entityInfo.maxLife = loc1.maxLife;
            _cache.role.entityInfo.maxMana = loc1.maxMana;
            RolePlayer.instance.updateLife(_cache.role.entityInfo.life, loc1.maxLife);
            RolePlayer.instance.updateMana(_cache.role.entityInfo.mana, loc1.maxMana);
            RolePlayer.instance.dispatchEvent(new PlayerEvent(PlayerEvent.UPDATEINFO, RolePlayer.instance));
            _cache.role.attackDistance = loc1.attackDistance;
            _cache.role.attackSpeed = loc1.attackSpeed;
            _cache.role.entityInfo.speed = loc1.speed;
            NetDispatcher.dispatchCmd(ServerCommand.EntityInfo_Update, arg1);
            return;
        }
    }
